using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreateBarrier : MonoBehaviour
{

    public List<GameObject> barriers;

    private readonly Vector2 barrierCreatePostion=new(14f,0f);
    private readonly float maxY=5f;
    private readonly float minY=-1.5f;

    private readonly int coolDate=4;
    private float sumTime=0;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        sumTime+=Time.deltaTime;
        if(sumTime>coolDate)
        {
            sumTime=0;
            int range=Random.Range(0,barriers.Count);
            GameObject barrierObj=Instantiate(barriers[range]);
            barrierObj.transform.parent=this.transform;
            float y=Random.Range(minY*100,maxY*100)/100;
            barrierObj.transform.localPosition=new(barrierCreatePostion.x,y);
        }
    }
}
